package com.by.controller;

import com.by.ResultBean;
import com.by.core.controller.BaseController;
import com.by.entity.Spu;
import com.by.service.SpuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author ServivE
 * @version 0.1
 * @className SpuController
 * @description
 * @date 2024/11/11 15:13
 * @since jdk17
 */
@RestController
@RequestMapping("/api/product")
@Api(tags = "spu产品管理")
public class SpuController extends BaseController {
    @Autowired
    SpuService spuService;

    @PostMapping("/spu")
    @ApiOperation("保存商品")
    public ResultBean save(@Validated @RequestBody Spu spu, BindingResult result) {
        validate(result);//校验

        int i = spuService.saveEntity(spu);
        return saveResult(i);
    }
    @ApiOperation("商品详情")
    @GetMapping("/spu")
    public ResultBean get(@RequestParam(name = "id",required = true) int id){
        Map map=spuService.getDetail(id);
        return success("商品详情",map);
    }

}
